<?php 
   
   /**
    * tableMySql class
    * @author Ta Van Chinh
    * @since 2/1/2014
   */
   class TableMySql{
      public $array_columns = array();
      public $array_fields = array();
      public $table_name = '';
      
      /**
       * 
       * The constructor
      */
      public function __construct($tableName,$arr_field = null){
         $this->table_name = $tableName;
         if(!is_null($arr_field)){
             $this->getColumnTable($arr_field);
         }else{
             $this->getColumnTable();
         }
        
         $this->getFieldTable();
      }
      
      /**
       * Get columns table
       * @param $tableName string
       * @return array
      */
      public function getColumnTable($conf = 'all'){
         $array_columns = array();
            if($this->table_name != ''){
               if($conf == 'all'){
                  $str_access = "SHOW COLUMNS FROM " . $this->table_name;   
               }else{
                  $str_access = "SHOW COLUMNS FROM " . $this->table_name . " WHERE ";
                  $field = '';
                  foreach($conf as $value){
                     $field .= " Field = '".$value."' OR";
                  }
                  $field = substr($field,0,-2);
                  $str_access .= $field;
               }
               $db_access = new db_query($str_access);
               $array_columns = $db_access->resultArray();
               $this->array_columns = $array_columns;
            }
      }
      
      /**
       * Get fields table
       * @param $tableName string
       * @return array
      */
      public function getFieldTable(){
         $array_columns = $this->array_columns;
         if(count($this->array_columns) > 0){
            foreach($this->array_columns as $value){
               $arr[] = $value['Field'];
            }
            $this->array_fields = $arr;
         }
      }
      
      /**
       * 
       * Gen html form add
      */
      public function genFormAdd(){
         if(count($this->array_columns) > 0){
            
            foreach($this->array_columns as $value){
               
            }
         }   
      }
   }
?>